////////////////////////////////////////////////////////////////////////////////
// Copyright 2006 CORE Solutions Limited
// All rights reserved.
// PROPRIETARY AND CONFIDENTIAL INFORMATION.
// Use is subject to license terms.
//
// FUNCTION ID      :   CODE
// AUTHOR           :   Saint Peng 
// DATE CREATE      :   2006/01/05
// DESCRIPTION      :   a SEARCH ACTION file for the function, CODE
//                  :   
//                  :   
//                  :   
//
// MODIFICATION HISTORY:
// DATE         AUTHOR          VERSION NO.         COMMENT
// -----------  --------------  ------------------  -------------------
// 2006/01/05   Saint Peng      1.0                 source is generated.
//
//
//
////////////////////////////////////////////////////////////////////////////////

package com.erp.app.setup.catalogOption.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.erp.app.common.ProjectConstants;
import com.erp.app.setup.catalogOption.criteria.CatalogOptionHdrSrchCriteria;
import com.erp.app.setup.catalogOption.pk.CatalogOptionHdrPk;
import com.erp.app.setup.catalogOption.vo.CatalogOptionHdrVo;
import com.erp.app.util.web.WebUtil;
import com.erp.framework.controller.action.SimpleSearchStyleAction;
import com.erp.framework.model.pk.SimpleBasePk;
import com.erp.framework.util.logger.Logger;
import com.erp.framework.util.user.User;

/**
* A <strong>Search Action</strong> is an adapter between the contents of an incoming
* HTTP request and the corresponding business logic that should be executed to
* process this request.  The controller (ActionServlet) will select an
* appropriate Action for each request.
* The main purpose for this action class is to handle the user search events
* from the web browsers.
*
* @author          Saint Peng 
* @version 1.0     2006/01/05
* @since           FrameWork 1.0
*
*/
public class CatalogOptionSearchAction extends SimpleSearchStyleAction {

	////////////////////////////////////////////////////////////////////////////////
	// CONSTANTS DEFINITION
	////////////////////////////////////////////////////////////////////////////////

	//public static final String ACTION_DO_SOMETHING = "actionDoSomething";
	//public static final String STATUS_DO_SOMETHING = "statusDoSomething";

	public static final int TAB_IDX_DTL = 0;


	////////////////////////////////////////////////////////////////////////////////
	// GLOBAL VARIABLES DEFINITION
	////////////////////////////////////////////////////////////////////////////////



	////////////////////////////////////////////////////////////////////////////////
	// LOGICAL AND BUSINESS METHODS
	////////////////////////////////////////////////////////////////////////////////

	public ActionForward handlePageEvent(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CatalogOptionSearchForm form = (CatalogOptionSearchForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {
//			if (!isHandled(request) && action.equalsIgnoreCase(ACTION_DO_SOMETHING)) {
//				actionForward = processActionDoSomething(mapping, formIn, request, response, errors);
//				setHandled(request);
//				saveToken(request);
//			}

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}

		return actionForward;
	}

	protected ActionForward processOtherStatus(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response,
		ActionErrors errors, String rb_status) {

		HttpSession session = request.getSession(false);
		CatalogOptionSearchForm form = (CatalogOptionSearchForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {
//			if (rb_status.equalsIgnoreCase(STATUS_DO_SOMETHING)) {
//				return processStatusDoSomething(mapping,  formIn,  request, response,  errors,  rb_status);
//			}
		} catch (Exception e) {
			Logger.log(this, e);
		}

		return actionForward;
	}

	//uncomment the following code and implement the method if necessary
	/*
	protected ActionForward processActionDoSomething(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CatalogOptionSearchForm form = (CatalogOptionSearchForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try{
			System.out.println("You are in processActionDoSomething().");
		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}

		return actionForward;
	}
	*/

	//uncomment the following code and implement the method if necessary
	/*
	protected ActionForward processStatusDoSomething(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response,
		ActionErrors errors, String rb_status) {

		HttpSession session = request.getSession(false);
		CatalogOptionSearchForm form = (CatalogOptionSearchForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try{
			System.out.println("You are in processStatusDoSomething().");
		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}

		return actionForward;
	}
	*/

	////////////////////////////////////////////////////////////////////////////////
	// END OF LOGICAL AND BUSINESS METHODS
	////////////////////////////////////////////////////////////////////////////////


	////////////////////////////////////////////////////////////////////////////////
	// OVERRIDES PARENT'S OPTIONAL METHODS
	////////////////////////////////////////////////////////////////////////////////

	//the following method is only to be overwritten by sub-class if intended
	//to set the aut-search on-load to on/off
	protected boolean getLoadOnEnter() {

		//auto-search when load
		return true;
	}

	//the following method is only to be overwritten by sub-class if intended
	//to set the clearing search result sets on-load to on/off
	protected boolean getResetOnEnter() {

		//reset last searched results when load 
		return false;
	}

	protected void initAction(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		super.initAction(mapping, formIn, request, response, errors);

		HttpSession session = request.getSession(false);
		CatalogOptionSearchForm form = (CatalogOptionSearchForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void initForm(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		super.initForm(mapping, formIn, request, response, errors);

		HttpSession session = request.getSession(false);
		CatalogOptionSearchForm form = (CatalogOptionSearchForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void initPage(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		super.initPage(mapping, formIn, request, response, errors);

		HttpSession session = request.getSession(false);
		CatalogOptionSearchForm form = (CatalogOptionSearchForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void beforeEdit(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CatalogOptionSearchForm form = (CatalogOptionSearchForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

			//TODO: Add the following line to ProjectSecurityConstants.java
			//public static final String SP_SHARE_CATALOG_OPTION = "SP_SHARE_CATALOG_OPTION";
			String companyCode = WebUtil.getAppropriateCompanyCode(session, ProjectConstants.SP_SHARE_CATALOG_OPTION);
			form.setSrchCompanyCode(companyCode);

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void afterEdit(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CatalogOptionSearchForm form = (CatalogOptionSearchForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void beforeSearch(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CatalogOptionSearchForm form = (CatalogOptionSearchForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected void afterSearch(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CatalogOptionSearchForm form = (CatalogOptionSearchForm) formIn;
		String action = form.getPageEvent();
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	protected String getSimpleSrchMenuId() {

		//TODO: Add the following line to ProjectMenuConstants.java
		//public static final String MOD_CATALOG_OPTION = "MOD_CATALOG_OPTION";
		return ProjectConstants.MOD_CATALOG_OPTION;
	}

	////////////////////////////////////////////////////////////////////////////////
	// END OF OPTIONAL METHODS
	////////////////////////////////////////////////////////////////////////////////


	////////////////////////////////////////////////////////////////////////////////
	// IMPLEMENTS PARENT'S ABSTRACT METHODS
	////////////////////////////////////////////////////////////////////////////////

	protected String getModuleName(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request,HttpServletResponse response) {

		//TODO: Add the following line to ProjectMenuConstants.java
		//public static final String MOD_CATALOG_OPTION = "MOD_CATALOG_OPTION";
		return ProjectConstants.MOD_CATALOG_OPTION;
	}

	protected String getFunctionId() {

		//struts-config xxxxx.do
		return "catalogOptionSearch.do";
	}

	protected Class getMasterFormClass() {

		//the corresponding form class
		return CatalogOptionSearchForm.class;
	}

	protected Class getMasterVOClass() {

		//corresponding master vo class
		return CatalogOptionHdrVo.class;
	}

	protected Class getSearchCriteriaClass() {

		//corresponding searching criteria class
		return CatalogOptionHdrSrchCriteria.class;
	}

	protected void setOtherCriteria(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response,
		ActionErrors errors, Object criteria) {

		HttpSession session = request.getSession(false);
		User user = (User) session.getAttribute(ProjectConstants.SESSION_USER);
		CatalogOptionHdrSrchCriteria crit = (CatalogOptionHdrSrchCriteria) criteria;

		//TODO: Add the following line to ProjectSecurityConstants.java
		//public static final String SP_SHARE_CATALOG_OPTION = "SP_SHARE_CATALOG_OPTION";
		String companyCode = WebUtil.getAppropriateCompanyCode(session, ProjectConstants.SP_SHARE_CATALOG_OPTION);

		crit.setSrchCompanyCode(companyCode);
		crit.setSearchResult(true);
	}

	protected String getMasterFormSessionName() {

		return "catalogOptionSearchForm";
	}

	protected SimpleBasePk getPk(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		CatalogOptionSearchForm form = (CatalogOptionSearchForm) formIn;
		CatalogOptionHdrPk pk = null;
//		edit the following with appropriate form field names
		pk = new CatalogOptionHdrPk(form.getSrchCompanyCode(), form.getEditCodeNo());

		return pk;
	}

	protected void setFormType(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
		HttpServletResponse response, ActionErrors errors){

		CatalogOptionSearchForm form = (CatalogOptionSearchForm) formIn;
		form.setFormType(ProjectConstants.FORM_TYPE_SEARCH);
	}

	////////////////////////////////////////////////////////////////////////////////
	// END OF ABSTRACT METHODS
	////////////////////////////////////////////////////////////////////////////////

}

